<html>
<body>
<h2>Hello World!</h2>

手机：<input type="text" name="phone" id="reg_mobile_">
<span id="reg_mobile_tip"></span>

<script src="js/jquery-3.2.1.min.js"></script>
<script>
    $(function () {
        var phone = false;
        var pwd = false;

        //手机号验证
        $("#reg_mobile_").blur(function(){
            var val = $("#reg_mobile_");//手机
            var tip = $("#reg_mobile_tip");//提示标签
            var regexp_mobile=/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0-9]|17[0-9])\d{8}$/;
            if (regexp_mobile.test(val.val())){
                $.ajax({
                    url:"user/checkphone",
                    type: "post",
                    cache: false,
                    async: true,
                    data:{ phone:val.val() },
                    dataType: "text",
                    success: function(b) {
                        if (b==0){
                            tip.html("该用户可以注册");
                            tip.css("color","green");
                            phone = true;
                        } else {
                            tip.html("该用户已被注册");
                            tip.css("color","red");
                        }
                    }
                })
            }else {
                tip.html("用户名错误!");
                tip.css("color","red");
            }

        });
    })
</script>
</body>
</html>
